﻿var queueSize = 0;
var lastFileID = null;
var tmpArrFile = {};
var arrFiles = [];

$(window).load(function() {
    $("#" + fileUpCtrl).uploadify({
        'swf': 'scripts/uploadify.swf',
        'buttonText': 'Browse Files',
        'uploader': 'uploadHandler.ashx',
        'folder': 'images/upload',
        'fileTypeDesc': 'Excel Files',
        'fileTypeExts': '*.xls;*.xlsx;',
        'multi': false,
        'height': 18,
        'auto': true,
        'fileSizeLimit': '5MB',
        'onQueueComplete': function(data) {
            //alert('Upload data successfully');
        },
        'onSelectError': function(file) {
            return false;
        },
        'onSelect': function(file) {
            queueSize++;
            $('#queuesize').val(queueSize);
            lastFileID = file.id;

        },
        'onUploadSuccess': function(file, data, response) {
            tmpArrFile = {
                "FileName": data,
                "FileSize": file.size,
                "FileType": file.type
            }
            arrFiles.push(tmpArrFile);
            ProcessChecking();
            //GetDataExcel();
        },
        'onDialogClose': function(queueData) {
            if (parseFloat(queueData.queueSize) > 5242880) {
                var errMsg = "File exceeds 5MB limit:\nLast file in queue will not be added";
                alert(errMsg);
                $("#" + fileUpCtrl).uploadify('cancel', lastFileID);
            }
        },
        'onCancel': function(file) {
            var idxFile = file.index;
            arrFiles.splice(idxFile, 1);

            queueSize--;
            $('#queuesize').val(queueSize);
        }
    });
});